package com.genesis.web.controller;


import com.genesis.mall.common.Result;
import com.genesis.mall.dto.OmsOrderReturnApplyDto;
import com.genesis.mall.dto.OrderReturnApply;
import com.genesis.mall.dto.PageDto;
import com.genesis.mall.entity.OmsOrderReturnApply;
import com.genesis.mall.service.IOmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private IOmsOrderReturnApplyService omsOrderReturnApplyService;



    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result deleteByIds(@RequestParam List<Long> ids) {

        boolean flag = omsOrderReturnApplyService.deleteByIds(ids);
        if (flag) {
            return Result.success();
        }
        return new Result(0,"操作失败","");
    }


    /**
     * 分页查询退货查询  精确查找
     *
     * @param orderReturnApply
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result<PageDto<OmsOrderReturnApply>> page(OrderReturnApply orderReturnApply, Integer pageNum, Integer pageSize) {

        return Result.success(omsOrderReturnApplyService.getList(orderReturnApply, pageNum, pageSize));

    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param omsOrderReturnApply
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result updateStatus(@PathVariable Long id,
                               @RequestBody OmsOrderReturnApply omsOrderReturnApply) {

        omsOrderReturnApplyService.updateStatus(id, omsOrderReturnApply);

        return Result.success();
    }


    /**
     * 获取退货申请详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OmsOrderReturnApplyDto> returnInfo(@PathVariable Long id) {

        OmsOrderReturnApplyDto omsOrderReturnApplyDto = omsOrderReturnApplyService.getInfo(id);

        return Result.success(omsOrderReturnApplyDto);
    }


    /**
     * 手机端申请退货
     * @param omsOrderReturnApply
     * @return
     */

    @PostMapping("/create")
    public Result returnApply(@RequestBody OmsOrderReturnApply omsOrderReturnApply) {
        //1.
        omsOrderReturnApplyService.save(omsOrderReturnApply);

        return  Result.success("");
    }

}
